//
//  PaotuiDetailViewController.m
//  rrqs
//
//  Created by 杜文杰 on 2018/8/30.
//

#import "PaotuiDetailViewController.h"
#import "UnusualAlertView.h"



#define BGCOLOR "F1F1F1"

@interface PaotuiDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *mainTableView; // 主框架
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIView *footerView;
@property (nonatomic, strong) UILabel *orderIdLabel; // 订单编号
@property (nonatomic, strong) UILabel *payTypeLabel;// 支付方式
@property (nonatomic, strong) UILabel *titleLabel;// 店铺名
@property (nonatomic, strong) UILabel *dateLabel; // 下单日期
@property (nonatomic, strong) UILabel *totalMoneyLabel;// 总计金额
@property (nonatomic, strong) UIButton *bottomBtn; // 地址
@property (nonatomic, strong) NSString *site_phoneStr; // 联系商家
@property (nonatomic, strong) NSString *gkPhoneStr; // 联系顾客
@property (nonatomic, strong) UIButton *sjBtn; // 联系商家
@property (nonatomic, strong) UIButton *gkBtn; // 联系顾客
@property (nonatomic, strong) UIButton *makeSureBtn; // 确认取货
@property (nonatomic, strong) UILabel *titleNameLabel; // 物品标题
@property (nonatomic, strong) UILabel *priceLabel; // 预期价格
@property (nonatomic, strong) UILabel *psfLabel; // 配送费
@property (nonatomic, strong) UILabel *xfLabel; // 小费
@property (nonatomic, strong) UILabel *zjLabel; // 总计
@property (nonatomic, strong) UILabel *juliLabel; // 距离
@property (nonatomic, strong) UILabel *bzContentLabel; // 备注

@property (nonatomic, strong) NSString *latitude; // 始发地
@property (nonatomic, strong) NSString *longitude; // 始发地
@property (nonatomic, strong) NSString *destination; //导航目的地

@property (nonatomic, strong) UIButton *unusualBtn; // 异常上报

@property (nonatomic, strong) NSArray *unusualLabelArray; // 异常上报

@end

@implementation PaotuiDetailViewController
- (void)getLabelQueryData {
    
    NSDictionary* arg = @{@"ince":@"get_abnormal_reason"};
    [DBNet PostURL:kHost parameters:arg succeed:^(NSDictionary *data) {
        NSLog(@"-----%@",data);
        NSInteger flag = [[data objectForKey:@"status"]integerValue];
        if(flag == 1){
            
            self.unusualLabelArray = [NSArray arrayWithArray:[data objectForKey:@"list"]];
        }else{
            
            [self alertHUD:[data objectForKey:@"msg"]];
            
        }
        
        [self hidHUD];
        
    } failure:^(NSError *error) {
        [self alertHUD:@"网络异常"];
    }];
}
// 界面数据源
- (void)queryData {

    NSDictionary* arg = @{@"ince":@"get_order_info",@"order_id":self.waiMaiDodelHList.order_id,@"emp_id":[UserModel sharedInstanced].userId};
    [DBNet PostURL:kHost parameters:arg succeed:^(NSDictionary *data) {
        [WMHelper outPutJsonString:data];
        NSInteger flag = [[data objectForKey:@"status"]integerValue];
        NSDictionary* dict = [data objectForKey:@"data"];
        self.orderIdLabel.text = [NSString stringWithFormat:@"%@",dict[@"order_id"]];
        if ([dict[@"paytype"] isEqualToString:@"2"]) {
            self.payTypeLabel.text = @"微信支付";
        }else
        {
            self.payTypeLabel.text = @"其他支付";
        }
        self.bzContentLabel.text = dict[@"order_mark"];
        self.titleLabel.text = dict[@"site_name"];
        self.titleNameLabel.text = dict[@"title"];
        self.priceLabel.text = [NSString stringWithFormat:@"商品预期价格￥%@",dict[@"price"]];
        self.psfLabel.text = dict[@"shipping_fee"];
        self.xfLabel.text = dict[@"fee"];
        self.zjLabel.text = dict[@"total_fee"];
        [self.bottomBtn setTitle:dict[@"address"] forState:UIControlStateNormal];
        self.juliLabel.text = [NSString stringWithFormat:@"%@km",self.waiMaiDodelHList.location];
       
//        if ([dict[@"status"] isEqualToString:@"7"]) {
//            [self.makeSureBtn setTitle:@"配送中" forState:UIControlStateNormal];
//            [self.makeSureBtn setBackgroundColor:getColor(@BGCOLOR)];
//            self.makeSureBtn .enabled = YES;
//        }
//        if ([dict[@"status"] isEqualToString:@"6"]) {
//            [self.makeSureBtn setTitle:@"取货中" forState:UIControlStateNormal];
//            [self.makeSureBtn setBackgroundColor:getColor(@BGCOLOR)];
//            self.makeSureBtn .enabled = YES;
//        }
        if ([dict[@"type"] isEqualToString:@"buy"]) {
            self.titleLabel.text = @"帮你买";
        }
        if ([dict[@"type"] isEqualToString:@"get"]) {
            self.titleLabel.text = @"帮你取";
        }
        if ([dict[@"type"] isEqualToString:@"send"]) {
            self.titleLabel.text = @"帮你送";
        }
        self.gkPhoneStr = dict[@"phone"];
        
        self.longitude = dict[@"send_lng"];
        self.latitude = dict[@"send_lat"];
        self.destination = dict[@"address"];
        
        
        
    } failure:^(NSError *error) {
        [self alertHUD:@"网络异常"];
    }];
}
//确认送达
-(void)makeSureDeliveryData{
    
    [self showHUD];
    
    NSDictionary* arg = @{@"ince":@"ex_send_food",
                          @"emp_id":self.Identity.userInfo.userID,
                          @"order_id":self.waiMaiDodelHList.order_id
                          
                          };
    [DBNet PostURL:kHost parameters:arg succeed:^(NSDictionary *data) {
        [WMHelper outPutJsonString:data];
        NSInteger flag = [[data objectForKey:@"status"]integerValue];
        if(flag == 1){
            NSString *sucess = data[@"sucess"];
            [self hidHUD: sucess success:YES complete:^{
                [self.navigationController popViewControllerAnimated:YES];
            }];
        }else{
            NSLog(@"%@",[data objectForKey:@"fail"]);
            [self hidHUD:[data objectForKey:@"fail"]];
        }

    } failure:^(NSError *error) {
        NSLog(@"%@",error.description);
        [self hidHUD:@"网络异常"];
    }];
}
//确认取货
- (void)makeSureQueryData {

    [self showHUD];

    NSString *typeStr;
    /**3代表帮你取 get； 2 代表帮你送 send ；1代表帮你买 buy*/
    if ([self.waiMaiDodelHList.type isEqualToString:@"get"]) {
        typeStr = @"3";
    }
    if ([self.waiMaiDodelHList.type isEqualToString:@"send"]) {
        typeStr = @"2";
    }
    if ([self.waiMaiDodelHList.type isEqualToString:@"buy"]) {
        typeStr = @"1";
    }
    NSDictionary* arg = @{
                          @"ince":@"ex_get_food",
                          @"order_id":self.waiMaiDodelHList.order_id,
                          @"emp_id":[UserModel sharedInstanced].userId,
                          @"type":typeStr
                          
                          };
    
    [DBNet PostURL:kHost parameters:arg succeed:^(NSDictionary *data) {
        
        NSLog(@"==== %@",data);
        NSInteger flag = [[data objectForKey:@"status"]integerValue];
        if(flag == 1){
            NSString *sucess = data[@"sucess"];
            [self hidHUD: sucess success:YES complete:^{
                [self.navigationController popViewControllerAnimated:YES];
            }];
        }else{
            NSLog(@"%@",[data objectForKey:@"fail"]);
            [self hidHUD:[data objectForKey:@"fail"]];
        }

    } failure:^(NSError *error) {
        [self hidHUD:@"网络异常"];
    }];
}
//确定上报
-(void)sureAbnormalUpload:(NSString *)text withMarkId:(NSString *)markId{
    
    [self showHUD];
    NSDictionary* arg = @{
                          @"ince":@"post_abnormal",
                          @"order_id":self.waiMaiDodelHList.order_id,
                          @"emp_id":[UserModel sharedInstanced].userId,
                          @"mark_id":markId,
                          @"reason":text
                          };
    [DBNet PostURL:kHost parameters:arg succeed:^(NSDictionary *data) {
        
        NSInteger flag = [[data objectForKey:@"status"]integerValue];
        if(flag == 1){
            
            NSLog(@"成功了没====%@",data);
            NSString *sucess = data[@"msg"];
            [self hidHUD: sucess success:YES complete:^{
                [self.navigationController popViewControllerAnimated:YES];
            }];
            
        }else{
            [self hidHUD:[data objectForKey:@"msg"]];
        }
        
    } failure:^(NSError *error) {
        [self hidHUD:@"网络异常"];
    }];
    
}
- (void) btnAction:(UIButton *)btn
{
    if ([btn isEqual:self.gkBtn]) {
        [self callPhone:self.gkPhoneStr];
    }
    if ([btn isEqual:self.makeSureBtn]) {
        if (self.isPeiSongz) { // 配送中  确认送达 接口
            [self makeSureDeliveryData];
        }else{
            [self makeSureQueryData]; // 待取货   确认取货 接口
        }
    }
    
    if ([btn isEqual:self.bottomBtn]) {
        
        [CommonUntils naviAddressWithDestination:self.destination withLatitude:self.latitude withLongitude:self.longitude withController:self];
    }
    
    if ([btn isEqual:self.unusualBtn]) {
        
        UnusualAlertView *alertView = [[UnusualAlertView alloc] initUnusualAlertWithData:self.unusualLabelArray];
        alertView.unusualHandleBlock = ^(NSString * _Nonnull text, NSString * _Nonnull markIdStr) {
            
            NSLog(@"text = %@",text);
            NSLog(@"markIdStr = %@",markIdStr);
            
            [self sureAbnormalUpload:text withMarkId:markIdStr];
        };
        
        [alertView showAlertView];
    }
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单详情";
    [self getLabelQueryData];
    [self queryData];
    [self.view addSubview:self.mainTableView];
    if (self.isPeiSongz) { // 配送中  确认送达 
        [self.makeSureBtn setTitle:@"确认送达" forState:UIControlStateNormal];
    }
}
#pragma mark -UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.01)];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.01)];
    return view;
}
#pragma mark - init
- (UITableView *)mainTableView
{
    if (!_mainTableView) {
        _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - SafeAreaBottomHeight - SafeAreaTopHeight) style:UITableViewStyleGrouped];
        _mainTableView.backgroundColor = getColor(@BGCOLOR);
        _mainTableView.tableHeaderView = self.headerView;
        _mainTableView.tableFooterView = self.footerView;
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        _mainTableView.showsVerticalScrollIndicator = NO;
        _mainTableView.showsHorizontalScrollIndicator = NO;
        _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        // 动态行高
        _mainTableView.rowHeight = UITableViewAutomaticDimension;
        // 预估行高
        _mainTableView.estimatedRowHeight = 80;
        [_mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
//        //刷新、加载
//        _mainTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//            [self queryData];
//        }];
    }
    return _mainTableView;
}
- (UIView *)headerView
{
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 440 / HEIGHT_6S_SCALE)];
        _headerView.backgroundColor = [UIColor whiteColor];
        __weak typeof(self) weakself = self;
        // 订单编号
        UILabel *orderIdLabel = [UILabel backLabelWithAlignment:@"1" contentStr:@"订单编号" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        [_headerView addSubview:orderIdLabel];
        [orderIdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_headerView.mas_top);
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(30 / HEIGHT_6S_SCALE);
        }];
        
        
        
        
        
        UILabel *copyLabel = [[UILabel alloc]init];
        [_headerView addSubview:copyLabel];
        [copyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_headerView).offset(-10 / WIDTH_6S_SCALE);
            make.centerY.equalTo(orderIdLabel.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(35, 18));
        }];
        copyLabel.textColor = COLORRGB(0x999999);
        copyLabel.text = @"复制";
        copyLabel.textAlignment = 1;
        copyLabel.font = kFontNameSize(11);
        copyLabel.layer.cornerRadius = 3;
        copyLabel.layer.masksToBounds = YES;
        copyLabel.layer.borderColor = COLORRGB(0x999999).CGColor;
        copyLabel.layer.borderWidth = 1;
        [copyLabel setUserInteractionEnabled:YES];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAciton)];
        [copyLabel addGestureRecognizer:tap];
        
        
        self.orderIdLabel = [UILabel backLabelWithAlignment:@"2" contentStr:@"" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        [_headerView addSubview:self.orderIdLabel];
        [self.orderIdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.height.equalTo(orderIdLabel);
            make.right.equalTo(copyLabel.mas_left).offset(-10 / WIDTH_6S_SCALE);
        }];
        
        
        // 支付方式
        UILabel *payTypeLabel = [UILabel backLabelWithAlignment:@"1" contentStr:@"支付方式" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        [_headerView addSubview:payTypeLabel];
        [payTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(orderIdLabel.mas_bottom);
            make.left.height.equalTo(orderIdLabel);
        }];
        
        
        self.payTypeLabel =  [UILabel backLabelWithAlignment:@"2" contentStr:@"微信支付" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        [_headerView addSubview:self.payTypeLabel];
        [self.payTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.height.equalTo(payTypeLabel);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
        }];
        
        
        
        
        // 横线
        UIView *lineView1 = [[UIView alloc]initWithFrame:CGRectZero];
        lineView1.backgroundColor = getColor(@BGCOLOR);
        [_headerView addSubview:lineView1];
        [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(payTypeLabel.mas_bottom);
            make.left.right.equalTo(weakself.headerView);
            make.height.mas_equalTo(10 / HEIGHT_6S_SCALE);
        }];
        // b备注
        UILabel *bzLabel = [UILabel backLabelWithAlignment:@"1" contentStr:@"备注:" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        [_headerView addSubview:bzLabel];
        [bzLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView1.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(40 / WIDTH_6S_SCALE);
        }];
        // 备注内容
        UILabel *bzContentLabel = [UILabel backLabelWithAlignment:@"1" contentStr:@"" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        bzContentLabel.textColor = [UIColor redColor];
        self.bzContentLabel = bzContentLabel;
        [_headerView addSubview:bzContentLabel];
        [bzContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bzLabel);
            make.left.equalTo(bzLabel.mas_right).offset(5 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(100 / WIDTH_6S_SCALE);
        }];
        
        // 横线
        UIView *lineView2 = [[UIView alloc]initWithFrame:CGRectZero];
        lineView2.backgroundColor = getColor(@BGCOLOR);
        [_headerView addSubview:lineView2];
        [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bzContentLabel.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(weakself.headerView);
            make.height.mas_equalTo(10 / HEIGHT_6S_SCALE);
        }];
        // 店名
        UILabel *titleLabel = [UILabel backLabelWithAlignment:@"1" contentStr:@"" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        titleLabel.textColor = [UIColor redColor];
        self.titleLabel = titleLabel;
        [_headerView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView2.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(SCREEN_WIDTH - 100 / WIDTH_6S_SCALE - 20 / WIDTH_6S_SCALE);
        }];
        // 日期时间
        UILabel *dateLabel = [UILabel backLabelWithAlignment:@"2" contentStr:@"" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        self.dateLabel = dateLabel;
        [_headerView addSubview:dateLabel];
        [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.titleLabel);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo(120 / WIDTH_6S_SCALE);
        }];
        // 横线
        UIView *lineView3 = [[UIView alloc]initWithFrame:CGRectZero];
        lineView3.backgroundColor = getColor(@BGCOLOR);
        [_headerView addSubview:lineView3];
        [lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(_headerView);
            make.height.mas_equalTo(1 / HEIGHT_6S_SCALE);
        }];
        // 代购商品名
        UILabel *titleNameLabel = [UILabel backLabelWithAlignment:@"1" contentStr:@"" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        self.titleNameLabel = titleNameLabel;
        [_headerView addSubview:titleNameLabel];
        [titleNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView3.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView.mas_left).offset(10 / HEIGHT_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
        // 商品预期价格
        UILabel *priceLabel = [UILabel backLabelWithAlignment:@"1" contentStr:@"" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        self.priceLabel = priceLabel;
        [_headerView addSubview:priceLabel];
        [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleNameLabel.mas_bottom);
            make.left.equalTo(_headerView.mas_left).offset(10 / HEIGHT_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
        // 出示小票予客户进行结算
        UILabel *xpLabel = [UILabel backLabelWithAlignment:@"1" contentStr:@"(出示小票予客户进行结算)" bgcolor:whiteColor fontSize:DEF_FontSize_13];
        xpLabel.textColor = getColor(textColor);
        [_headerView addSubview:xpLabel];
        [xpLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(priceLabel.mas_bottom);
            make.left.equalTo(_headerView.mas_left).offset(10 / HEIGHT_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
        // 横线
        UIView *lineView4 = [[UIView alloc]initWithFrame:CGRectZero];
        lineView4.backgroundColor = getColor(@BGCOLOR);
        [_headerView addSubview:lineView4];
        [lineView4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(xpLabel.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(_headerView);
            make.height.mas_equalTo(1 / HEIGHT_6S_SCALE);
        }];
        // 配送费
        NSMutableArray *marray = @[].mutableCopy;
        marray = [self backUIViewWitTextStr:@"配送费"];
        UIView *psfView = marray[0];
        [_headerView addSubview:psfView];
        [psfView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView4.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(_headerView);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
        self.psfLabel = marray[1];
        self.psfLabel.text = @"$100";
        // 小费
        [marray removeAllObjects];
        marray = [self backUIViewWitTextStr:@"小费"];
        UIView *xfView = marray[0];
        [_headerView addSubview:xfView];
        [xfView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(psfView.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(_headerView);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
        self.xfLabel = marray[1];
        // 总计
        [marray removeAllObjects];
        marray = [self backUIViewWitTextStr:@"总计"];
        UIView *zjView = marray[0];
        [_headerView addSubview:zjView];
        [zjView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(xfView.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(_headerView);
            make.height.mas_equalTo(20 / HEIGHT_6S_SCALE);
        }];
        self.zjLabel = marray[1];
        
        UIButton *gkBtn = [[UIButton alloc]init];
        [gkBtn setBackgroundColor:getColor(@"1EBEA8")];
        [gkBtn setTitleColor:getColor(blackColor) forState:UIControlStateNormal];
        gkBtn.titleLabel.font = DEF_FontSize_14;
        [gkBtn setTitle:@"联系顾客" forState:UIControlStateNormal];
        [gkBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        self.gkBtn = gkBtn;
        [_headerView addSubview:gkBtn];
        [gkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zjLabel.mas_bottom).offset(20 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView.mas_left).offset(10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(40 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo((SCREEN_WIDTH - 40 / WIDTH_6S_SCALE) / 2);
        }];
        UIButton *makeSureBtn = [[UIButton alloc]init];
        [makeSureBtn setBackgroundColor:getColor(@"F7AB3B")];
        [gkBtn setTitleColor:getColor(blackColor) forState:UIControlStateNormal];
        makeSureBtn.titleLabel.font = DEF_FontSize_14;
        [makeSureBtn setTitle:@"确认取货" forState:UIControlStateNormal];
        [makeSureBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        self.makeSureBtn = makeSureBtn;
        [_headerView addSubview:makeSureBtn];
        [makeSureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zjLabel.mas_bottom).offset(20 / HEIGHT_6S_SCALE);
            make.right.equalTo(_headerView.mas_right).offset(-10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(40 / HEIGHT_6S_SCALE);
            make.width.mas_equalTo((SCREEN_WIDTH - 40 / WIDTH_6S_SCALE) / 2);
        }];
        // 横线
        UIView *lineView5 = [[UIView alloc]initWithFrame:CGRectZero];
        lineView5.backgroundColor = getColor(@BGCOLOR);
        [_headerView addSubview:lineView5];
        [lineView5 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(makeSureBtn.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(_headerView);
            make.height.mas_equalTo(1 / HEIGHT_6S_SCALE);
        }];
        
        
        
        UIView *bottomView = [[UIView alloc]initWithFrame:CGRectZero];
        [_headerView addSubview:bottomView];
        [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView5.mas_bottom);
            make.left.right.equalTo(_headerView);
            make.height.mas_equalTo(30 / HEIGHT_6S_SCALE);
        }];
        
        
        UIImageView *locationImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_dingwei_black"]];
        [bottomView addSubview:locationImage];
        [locationImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(bottomView);
            make.left.equalTo(bottomView).offset(5);
            make.height.width.mas_equalTo(20);
        }];
        
        // 代购商品名
        UILabel *juliLabel = [UILabel backLabelWithAlignment:@"1" contentStr:@"27.6km" bgcolor:whiteColor fontSize:DEF_FontSize_14];
        juliLabel.textColor = getColor(@"F7AB3B");
        self.juliLabel = juliLabel;
        juliLabel.textAlignment = NSTextAlignmentRight;
        [bottomView addSubview:juliLabel];
        [juliLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(80);
            make.right.equalTo(bottomView).offset(-10);
            make.top.height.equalTo(bottomView);
        }];
        
        
        UIButton *bottomBtn = [[UIButton alloc]init];
        bottomBtn.backgroundColor = getColor(whiteColor);
        [bottomBtn setTitleColor:getColor(textColor) forState:UIControlStateNormal];
        bottomBtn.titleLabel.font = DEF_FontSize_13;
        bottomBtn.titleLabel.numberOfLines = 0;
        bottomBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//        [bottomBtn setTitle:@"新民市东环街41号" forState:UIControlStateNormal];
        [bottomBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        self.bottomBtn = bottomBtn;
        [bottomView addSubview:bottomBtn];
        [bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(bottomView);
            make.left.equalTo(locationImage.mas_right);
            make.right.equalTo(juliLabel.mas_left);
        }];
        
       
        
    }
    return _headerView;
}
- (UIView *)footerView
{
    if (!_footerView) {
        _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100/ HEIGHT_6S_SCALE)];
        _footerView.backgroundColor = [UIColor clearColor];
        
        
        UIButton *unusualBtn = [[UIButton alloc]init];
        unusualBtn.backgroundColor = getColor(@"f5964f");
        [unusualBtn setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
        unusualBtn.titleLabel.font = DEF_FontSize_16;
        [unusualBtn setTitle:@"异常上报" forState:UIControlStateNormal];
        [unusualBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        unusualBtn.layer.cornerRadius = 5;
        unusualBtn.layer.masksToBounds = YES;
        self.unusualBtn = unusualBtn;
        [_footerView addSubview:unusualBtn];
        [unusualBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_footerView).offset(50 / HEIGHT_6S_SCALE);
            make.centerX.equalTo(self.footerView);
            make.width.equalTo(self.footerView).multipliedBy(0.6);
            make.height.mas_equalTo(45/ HEIGHT_6S_SCALE);
            
        }];
        
        
        
    }
    return _footerView;
}
/**
 *  拨打电话
 *
 *  @param phoneNumber 号码
 */
- (void)callPhone:(NSString *)phoneNumber{
    
    NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"tel:%@",phoneNumber];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
    
//    UIAlertController *av = [UIAlertController alertControllerWithTitle:@"拨打电话" message:nil preferredStyle:UIAlertControllerStyleAlert];
//    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phoneNumber]]];
//    }];
//    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//
//    }];
//    [av addAction:action1];
//    [av addAction:action2];
//    [self presentViewController:av animated:YES completion:nil];
}
- (NSMutableArray *)backUIViewWitTextStr:(NSString *)textStr
{
    NSMutableArray *mArray = @[].mutableCopy;
    
    UIView *baseView = [[UIView alloc]init];
    baseView.backgroundColor = [UIColor clearColor];
    UILabel *leftLabel = [UILabel backLabelWithAlignment:@"1" contentStr:textStr bgcolor:whiteColor fontSize:DEF_FontSize_13];
    leftLabel.textColor = getColor(textColor);
    [baseView addSubview:leftLabel];
    leftLabel.frame = CGRectMake(10 / WIDTH_6S_SCALE,(baseView.frame.size.height * 0.5) - (leftLabel.frame.size.height * 0.5), 150 / WIDTH_6S_SCALE, 20 / HEIGHT_6S_SCALE);
    
    UILabel *rightLabel = [UILabel backLabelWithAlignment:@"2" contentStr:@"￥9" bgcolor:whiteColor fontSize:DEF_FontSize_13];
    rightLabel.textColor = getColor(textColor);
    [baseView addSubview:rightLabel];
    rightLabel.frame = CGRectMake(SCREEN_WIDTH - 150 / WIDTH_6S_SCALE - 10,(baseView.frame.size.height * 0.5) - (rightLabel.frame.size.height * 0.5), 150 / WIDTH_6S_SCALE, 20 / HEIGHT_6S_SCALE);
    [mArray addObject:baseView];
    [mArray addObject:rightLabel];
    return mArray;
}

-(void)tapAciton{
    
    
    [self alertHUD:@"复制成功"];
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = [Config isBlankString:[NSString stringWithFormat:@"%@",self.orderIdLabel.text]] ? @"" : [NSString stringWithFormat:@"%@",self.orderIdLabel.text];
    NSLog(@"===%@",pasteboard.string);
    
}


@end
